package cn.bdqn.witcity.controller;

import cn.bdqn.witcity.entity.Role;
import cn.bdqn.witcity.service.RoleService;
import cn.bdqn.witcity.util.ResponseResult;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
public class RoleController {
    @Resource
    RoleService roleService;
    @RequestMapping("/sys/roles")
    @ResponseBody
    public ResponseResult roleMgr(Role role){

        int count=roleService.getRoleCount(role);
        List<Role> roleList=roleService.getAllRole(role);
        return new ResponseResult(0,"",roleList,count);
    }
    @RequestMapping("/saveRole")
    @ResponseBody
    public ResponseResult saveRole(Role role){
        int result=roleService.addRole(role);
        if(result>0){
            return new ResponseResult(200,"",result);
        }
        return new ResponseResult(0,"",result);
    }
    @RequestMapping("/updateRole")
    @ResponseBody
    public ResponseResult updateRole(Role role){
        int result=roleService.updateRole(role);
        if(result>0){
            return new ResponseResult(200,"",result);
        }
        return new ResponseResult(0,"",result);
    }
    @RequestMapping("/delRole")
    @ResponseBody
    public ResponseResult delRole(Integer id){
        int result=roleService.delRole(id);
        if(result>0){
            return new ResponseResult(200,"",result);
        }
        return new ResponseResult(0,"",result);
    }

}
